import { http } from './config';

export interface PageInfo<T> {
  list: T[];
  total: number;
  pageNum: number;
  pageSize: number;
}

export interface User {
  id: number | null;
  createTime: string | null;
  updateTime: string | null;
  account: string | null;
  name: string | null;
  password: string | null;
  bindPhone: string | null;
  bindEmail: string | null;
  role: string | null;
  avatar: string | null;
}

// 登录请求接口
export interface LoginRequest {
  account: string;
  password: string;
}

// 登录响应接口
export interface LoginResponse {
  user: User;
  token?: string;
  message?: string;
}

// 专门的登录接口
export const login = (loginData: LoginRequest) => {
  return http.post<LoginResponse>('/user/login', loginData);
};

// 标准接口一: 根据ID查询
export const selectById = (id: number | null) => {
  return http.get<User>(`/user/${id}`);
};

// 标准接口二: 分页查询全部
export const selectAll = (pageNum = 1, pageSize = 10) => {
  return http.get<PageInfo<User>>('/user', {
    params: { pageNum, pageSize }
  });
};

// 标准接口三: 新增
export const insert = (pojo: User) => {
  return http.post<User>('/user', pojo);
};

// 标准接口四: 删除
export const deleteById = (id: number) => {
  return http.delete<User>(`/user/${id}`);
};

// 标准接口五: 更新
export const update = (id: number | null, pojo: User) => {
  return http.put<User>(`/user/${id}`, pojo);
};

// 标准接口六: 条件查询
export const selectEq = (conditions: Record<string, any>) => {
  return http.post<User[]>('/user/select-eq', conditions);
};